package com.hfi.security.app.social;

import com.hfi.security.core.social.config.HfiSpringSocialConfigurer;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @author ChangLiang
 * @date 2019/9/3
 */
@Component
public class SpringSocialConfigurerPostProcessor implements BeanPostProcessor {

    public static final String HFI_SOCIAL_SECURITY_CONFIG_BEAN_NAME = "hfiSocialSecurityConfig";

    /**
     * 所有bean在初始化之前都会经过这个方法
     * @param o
     * @param s
     * @return
     * @throws BeansException
     */
    @Override
    public Object postProcessBeforeInitialization(Object o, String s) throws BeansException {
        return o;
    }

    /**
     * 所有bean在初始化之后都会经过这个方法
     * @param o
     * @param s
     * @return
     * @throws BeansException
     */
        @Override
        public Object postProcessAfterInitialization(Object o, String s) throws BeansException {
            if (StringUtils.equals(s, HFI_SOCIAL_SECURITY_CONFIG_BEAN_NAME)) {
                HfiSpringSocialConfigurer hfiSpringSocialConfigurer = (HfiSpringSocialConfigurer) o;
                hfiSpringSocialConfigurer.signupUrl("/social/signUp");
                return hfiSpringSocialConfigurer;
            }
            return o;
        }
}
